package com.xxl.controller.ApiImpl;

import com.xxl.controller.UserApi;
import com.xxl.dto.User;
import com.xxl.util.ResponseHandlerUtil;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * @author xxl
 * @date 2023/3/19
 */
@RestController
@Slf4j
public class UserApiController implements UserApi<Map<String, Object>> {
    /**
     * 模拟用户数据
     */
    public static HashMap<String, User> map = new HashMap<>(2);
    @Resource
    ResponseHandlerUtil<String> util;
    static {
        map.put("xxl", new User("xxl",19,new ArrayList<>()));
        map.put("wyx", new User("wyx",18,new ArrayList<>()));
    }
    @GetMapping("/login")
    @Override
    public Map<String, Object> login( String  username, String password)  {
        log.info("username="+username+",password="+username);
        return util.commonReturn("登录成功",200);
    }
    @PostMapping("/add")
    @Override
    @Validated
    public Map<String, Object> add(@RequestBody @Validated User user) {
        return util.commonReturn("增加成功",200);
    }
    @GetMapping("/delete/{key}")
    @Override
    public Map<String, Object> delete(@PathVariable("key") String key) {
        return util.commonReturn("删除成功",200);
    }
    @GetMapping("/query")
    @Override
    public Map<String, Object> query() {
        ResponseHandlerUtil<Map<String,User>> util1 = new ResponseHandlerUtil<>();
        return util1.commonReturn(map,200);
    }
}
